﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.Mvc;
using System.Data.Linq;
using DatingSoonMVC2008.Models;
using System.Web.Security;
using System.Web.Routing;

namespace DatingSoonMVC2008.Controllers
{
    public class HomeController : Controller
    {
        public IFacade Facade = new Facade();
        public IContext Context = new Context();

        public HomeController()
        { }
        public HomeController(IViewEngine viewEngine,IFacade facade)
        {
            this.ViewEngine = viewEngine;
            this.Facade = facade;
        }

        public void Index()
        {
            if (Context.IsAuthenticated)
                RenderView("Authenticated");
            else
                RenderView("Index");
        }

        public void LoginSubmit(string name, string password)
        {
            if (Facade.CheckCredentials(name, password))
            {
                Context.SetAuthenticationCookie(name);  
            }
            RedirectToAction("Index");

        }
    }
}
